package com.jn.photogallery.views;

import android.content.Intent;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import com.jn.photogallery.R;
import com.jn.photogallery.adapter.AvatarSecondAdapter;
import com.jn.photogallery.base.BaseActivity;
import com.jn.photogallery.contract.AvatarContact;
import com.jn.photogallery.entity.DayAvatar;
import com.jn.photogallery.presenter.AvatarPresenter;

import java.util.ArrayList;
import java.util.List;

public class AvatarShowActivity extends BaseActivity implements AvatarContact.AvatarView {
    private TextView textView ;
    private RecyclerView recyclerView ;
    private AvatarContact.AvatarPresenter mPresenter ;
    private AvatarSecondAdapter adapter ;
    private List<DayAvatar.AvatarFirstData> mList ;
    private List<DayAvatar.AvatarFirstData.AvatarSecondData> sList ;
    @Override
    public int getLayoutId() {
        return R.layout.day_image;
    }

    @Override
    public void init() {
        String name = getIntent().getStringExtra("name");
        textView = findViewById(R.id.mTitle);
        recyclerView = findViewById(R.id.dListView);
        textView.setText(name);
        mPresenter = new AvatarPresenter(this , this);
        mPresenter.getData();
        recyclerView.setLayoutManager(new GridLayoutManager(this,2));
        mList = new ArrayList<>();
        sList = new ArrayList<>();


        adapter = new AvatarSecondAdapter( sList , this , this);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void showData(DayAvatar data) {
        String name = getIntent().getStringExtra("name");
        mList = data.getResult() ;
        for (DayAvatar.AvatarFirstData avatar : mList){
            Log.d("头像数据", avatar.getName());
            if (avatar.getName().equals(name)) {
                sList = avatar.getList() ;
            }
        }
        adapter.updateData(sList);
    }
}
